//
//  ChildVC.swift
//  SwfitDemo
//
//  Created by menchao on 2018/9/26.
//  Copyright © 2018年 Test. All rights reserved.
//

import UIKit
import SnapKit


class ChildVC: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
       
        
        self.view.addSubview(clickButton)
        self.view.addSubview(clickButton2)
        
        
        self.view.addSubview(self.userLbl)
        self.userLbl.snp.makeConstraints { make in
            make.left.equalTo(self.view).offset(30)
            make.top.equalTo(self.clickButton2.snp.bottom).offset(30)
        }
        
        //闭包
        self.testBiBao()
       self.testEnum()
        self.testStruct()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    
    typealias AddBlock = (Int,Int) ->Int
    
    
    // MARK: -  闭包
    func testBiBao(){
        let add1:(Int,Int)->Int = {
            (a,b) in
            return a+b
        }
        
        
        let add2:AddBlock = {
            (a,b) in
            return a+b
        }
        let result = add2(1100, 200);
        //打印闭包返回值
        print("result = \(result)");
    }
    
    
    
    @objc func clickMe(){
        
        NSLog("click me no argams", "haha")
        
        let alert = UIAlertController(title: "标题", message: "详情1", preferredStyle: UIAlertControllerStyle.actionSheet)
       
        let cancelAction = UIAlertAction(title: "取消", style: .cancel) { action in
             NSLog("cancelAction")
        }
        
        alert.addAction(cancelAction)
        self.present(alert, animated: true, completion: nil)
    }
    
    @objc func clickMe2(_ button: UIButton){
        NSLog("clickMe2 me :%d", button.tag)
        let nextPageVC  = NextParamsPageVC()
        nextPageVC.parmas = "我要传递参数100"
        nextPageVC.passValue = { (str) in
            print("我接收到了:\(str)")
            self.userLbl.text = str
        }
        self.navigationController?.pushViewController(nextPageVC, animated: true)
    }
    
    
    // MARK: - enum
    
    enum Sections: Int {
        case Header
        case Body
        case Footer
    }
    
    enum Rank: Int {
        case ace = 1
        case two, three, four, five, six, seven, eight, nine, ten
        case jack, queen, king
        func simpleDescription() -> String {
            switch self {
            case .ace:
                return "ace"
            case .jack:
                return "jack"
            case .queen:
                return "queen"
            case .king:
                return "king"
            default:
                return String(self.rawValue)
            }
        }
    }
    
    enum Rank11: String {
        case ace = "123"
        case two = "456"
        case jack = "789"
        case we = "011"
        func Rank11Description() -> String {
            switch self {
            case .ace:
                return "ace1111"
            case .two:
                return "jack111"
            case .jack:
                return "queen111"
            default:
                return String(self.rawValue)
            }
        }
    }
    
    func testEnum(){
        let ace = Rank.two
        let ace1 = Rank.three
        print(ace)
        print(ace1)
        print(ace1.rawValue)
        print(ace1.rawValue)
    }
    
    // MARK: - struct
    struct House {
        var count: Int
        var Width: CGFloat
        var Height: CGFloat
        func houseDescription() -> String {
            return "Width \(Width), Height: \(Height)"
        }
    }
    
    func testStruct(){
        let house = House(count: 2, Width: 100, Height: 200)
        print(house)
        print(house.houseDescription())
    }
    
    lazy var clickButton: UIButton = {
        let clickButton = UIButton(frame: CGRect.init(x: 0, y: 100, width: 300, height: 40))
        clickButton.setTitle("点我下，不传递触摸对象", for: UIControlState.normal)
        clickButton.backgroundColor = UIColor.blue
        clickButton.addTarget(self, action: #selector(clickMe), for: UIControlEvents.touchUpInside)
        return clickButton
    }()
    
    lazy var clickButton2: UIButton = {
        let clickButton = UIButton(frame: CGRect.init(x: 0, y: 160, width: 300, height: 40))
        clickButton.setTitle("点我下，传递数据给下一个页面", for: UIControlState.normal)
        clickButton.backgroundColor = UIColor.blue
        clickButton.tag = 1000
        clickButton.addTarget(self, action: #selector(clickMe2(_:)), for: UIControlEvents.touchUpInside)
        return clickButton
    }()
 
    lazy var userLbl: UILabel = {
        let label = UILabel()
        label.text = "I am snapkit for autolayout"
        return label
    }()

}
